package com.tbit.uqbike.webmanager.controller;

import com.tbit.uqbike.annos.OperateLog;
import com.tbit.common.constant.MethodEnum;
import com.tbit.common.constant.ModuleEnum;
import com.tbit.uqbike.object.pojo.AccountDepositBound;
import com.tbit.uqbike.object.view.JsonResult;
import com.tbit.uqbike.service.business.AccountDepositBoundService;
import com.tbit.uqbike.webmanager.util.Assert;
import com.tbit.uqbike.webmanager.util.StringUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 区域互通表(AccountDepositBound)表控制层
 *
 * @author jing
 * @since 2020-12-30 16:08:59
 */
@RestController
@RequestMapping("/accountdepositbound")
public class AccountDepositBoundController {
    /**
     * 服务对象
     */
    @Resource
    private AccountDepositBoundService AccountDepositBoundService;

    /**
     * 通过主键查询单条数据
     *
     * @param sourceAccountId 主键
     * @return 单条数据
     */
    @PostMapping("/selectList")
    public JsonResult selectList(Integer sourceAccountId, Integer type) {
        return JsonResult.ok(this.AccountDepositBoundService.queryById(sourceAccountId, type));
    }

    /**
     * @param AccountDepositBound
     * @return com.tbit.uqbike.object.view.JsonResult
     * @Description: 修改和增加卡区域互通
     * @createDate 2020/12/30 17:21
     */

    @PostMapping("/edit")
    @OperateLog(module = ModuleEnum.CARDSHARING, methods = MethodEnum.CARDSHARING_EDIT)
    public JsonResult edit(AccountDepositBound AccountDepositBound) {
        Assert.notNull(AccountDepositBound.getSourceAccountId(), "ver.areaId.notNull");
//        Assert.notNull(AccountDepositBound.getTargetAccountIds(), "ver.areaId.notNull");
        Assert.notNull(AccountDepositBound.getType(), "ver.AccountDepositBound.type.notNULL");
        List<Integer> accountIds = StringUtil.getIntegerList(AccountDepositBound.getTargetAccountIds());
        AccountDepositBound.setAccountIds(accountIds);
        AccountDepositBound.setBoundTime(new Date());
        AccountDepositBoundService.insert(AccountDepositBound);
        return JsonResult.ok();
    }

}